package com.mobilebsc.httpclient.callback;

import java.util.List;

import android.util.Log;

import com.loopj.android.http.RequestParams;
import com.mobilebsc.datatype.EDataType;
import com.mobilebsc.datatype.KPI;
import com.mobilebsc.exception.NotImplementedException;

public class KPIRestClientUsage implements IRestClientUsage<KPI>,
		IAsyncTaskCompleteListener<List<KPI>> {

	private static final String TAG = "KPIRestClientUsage";
	private IAsyncTaskCompleteListener<List<KPI>> callback;
	private String svcUrl;

	public KPIRestClientUsage(IAsyncTaskCompleteListener<List<KPI>> callback) {
		this.callback = callback;
		this.svcUrl = "kpis";
	}

	@Override
	public void onTaskComplete(List<KPI> result) {
		Log.i(TAG, "result[0].content: " + result.get(0).getId() + ", "
				+ result.get(0).getName() + ", "
				+ result.get(0).getDescription());

		callback.onTaskComplete(result);
	}

	@Override
	public void getAll() {
		KPIHttpResponseHandler httpResponseHandler = new KPIHttpResponseHandler(
				this);
		MbscRestClient.get(svcUrl, null, httpResponseHandler);

	}

	@Override
	public void getById(int kpiId) {
		KPIHttpResponseHandler httpResponseHandler = new KPIHttpResponseHandler(
				this);
		MbscRestClient.get(svcUrl, new RequestParams("id", kpiId),
				httpResponseHandler);
	}

	@Override
	public void add(KPI element) {
		throw new NotImplementedException();

	}

	@Override
	public void delete(KPI element) {
		throw new NotImplementedException();

	}

	public void getReferencedKPI(int referenceId,
			EDataType referenceType) {
		KPIReferencedByX_HttpResponseHandler httpResponseHandler = new KPIReferencedByX_HttpResponseHandler(
				this);
		switch (referenceType) {
			case StrategicGoal:				
				MbscRestClient.get(svcUrl + "/goal", new RequestParams("id",
						referenceId), httpResponseHandler);
				break;
			case WeakSignal:
				MbscRestClient.get(svcUrl + "/weaksignal", new RequestParams("id",
						referenceId), httpResponseHandler);
				break;
			default:
				throw new NotImplementedException();
				// break;
		}
	}
}